#!/bin/bash

IFS_BAK=$IFS
IFS="
"

inv="/Data/inventory"
invT="/Data/inventory/temp"
invRW1="/Data/inventory/temp/qgmraw1"
invRW2="/Data/inventory/temp/qgmraw2"
mediaA="/Data/MovieA/"
mediaB="/Data/MovieB/"
mediaC="/Data/MovieT1/"
mediaD="/Data/MovieT2/"

echo "Generating TVShow List....."

/usr/bin/find $mediaA -size +10M -exec ls -sdh --block-size=M {} + |sed -e 's#M \/Data\/# /\Data\/#' > $invRW1 
/usr/bin/find $mediaB -size +10M -exec ls -sdh --block-size=M {} + |sed -e 's#M \/Data\/# /\Data\/#' >> $invRW1 
/usr/bin/find $mediaC -size +10M -exec ls -sdh --block-size=M {} + |sed -e 's#M \/Data\/# /\Data\/#' >> $invRW1
/usr/bin/find $mediaD -size +10M -exec ls -sdh --block-size=M {} + |sed -e 's#M \/Data\/# /\Data\/#' >> $invRW1

echo "Transforming List to CSV file"

/usr/bin/sed -e 's/^/"/g' $invRW1 > $invRW2
/usr/bin/sed -e 's/\//","/g' $invRW2 > $invRW1
/usr/bin/sed -e 's/$/"/g' $invRW1 > $invRW2
/usr/bin/sed 's/\(.*\)\./\1","/' $invRW2 > $invRW1
/usr/bin/sed 's/\(.*\) [(]/\1","/' $invRW1 > $invRW2
/usr/bin/sed 's/\(.*\)[)]/\1/' $invRW2 > $invRW1

echo "Finalizing CSV File"

/bin/echo ""File Size \(MB\)","Root Directory","Sub Directory","Movie Directory","Movie Title","Year Released","Extention File"" > $inv/Movies`date +%F`.csv
/usr/bin/cat $invRW1 >> $inv/Movies`date +%F`.csv


echo "DONE Generating - `date`"
IFS=$IFS_BAK
IFS_BAK=
